<%--
  Created by IntelliJ IDEA.
  User: WeiHong
  Date: 2017/4/26
  Time: 10:29
--%>
<%@ page contentType="text/html; charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<html>
<head>
    <title>文件上传下载</title>
    <%@include file="../common/common.jsp" %>
</head>
<body>
<script type="text/javascript" src="${path}/static/zyupload/js/zyUpload.js"></script>
<link rel="stylesheet" href="${path}/static/zyupload/css/zyUpload.css" type="text/css">

<form method="post" action="${path}/fileLoad/uploadFile" enctype="multipart/form-data" >
    <input type="file" name="uploadfile">
    <input type="submit" value="上传">
</form>

<a href="javascript:void(0);" onclick="openUploadWindow()" title="上传图片">上传图片</a>
<div style="border-bottom: 1px solid #eee; width: 100%"></div>
<ul id='imgs-list-w' class="imgs-list-w"></ul>

<div id="uploadWin" style="display: none;">
    <div id="demo" class="demo"></div>
</div>
<img src="${path}/fileLoad/downloadFile">

<script type="text/javascript">

    var url;
    $(function () {
        url = "${path}/fileLoad/uploadFile";

//        loadScreenShotImages();

        $("#demo").zyUpload({
            width: "550px",                                   // 宽度
            height: "250px",                                  // 宽度
            itemWidth: "120px",                               // 文件项的宽度
            itemHeight: "100px",                              // 文件项的高度
            url: url,                                         // 上传文件的路径
            multiple: true,                                  // 是否可以多个文件上传
            dragDrop: true,                                  // 是否可以拖动上传文件
            del: true,                                       // 是否可以删除文件
            finishDel: false  				                 // 是否在上传文件完成后删除预览
        });
    });

    function loadScreenShotImages() {
        var contractId = $("#contractId").val();
        var param = {'contractId': contractId};
        var imageHtml = "<li><i id='{0}'></i><img height='150px' src='${path}/fileLoad/download/{0}' alt={1}><span>{2}</span></li>";
        $.ajax({
            url: '${path}/workflow/netCheck/queryNetCheckImages',
            data: param,
            type: 'post',
            success: function (data) {
                if (data.success) {
                    $('#imgs-list-w').empty();
                    var html = "";
                    $.each(data.result, function (i, item) {
                        html += $.format(imageHtml, item.id, item.displayName, item.displayName);
                    });
                    $('#imgs-list-w').append(html);
                    $('#imgs-list-w').viewer('destroy');
                    $('#imgs-list-w').viewer();
                    //绑定删除事件
                    $("#imgs-list-w>li>i").bind("click", function () {
                        var delId = $(this).attr("id");
                        $.messager.confirm("删除询问", "是否需要删除网查图片?", function (r) {
                            if (r) {
                                postReturnJson("${path}/workflow/processDocAttachment/delete/" + delId, {}, function (data) {
                                    if (data.success) {
                                        loadScreenShotImages();
                                    } else {
                                        showTipsBox('提示:', data.msg);
                                    }
                                });
                            }
                        });

                    });
                    checkLoadImg("imgs-list-w");
                }
            }
        });
    }

    //上传网查图片
    function openUploadWindow() {
        $('#uploadWin').dialog({
            title: '图片上传',
            width: '600px',
            height: '340px',
            modal: true,
            onClose: function () {
                loadScreenShotImages();
            }
        });
    }

</script>

</body>
</html>
